<?php
namespace app\index\controller;
use app\index\model\Course;
use app\index\model\Teacher;
use app\index\model\Student;
use think\Db;

class Select {
    public function getTeacher(){
        $res = input("post.");
        $data = Teacher::get($res["t_id"]);
        return $data;
    }

    public function getStudent(){
        $res = input("post.");
        $data = Student::get($res["s_id"]);
        return $data;
    }

    public function getAllCourse(){
        $data = Course::all();
        return $data;
    }

    public function getTeacherCourse(){
        $res = input("post.");
        $data = Course::all(["t_id" => $res["t_id"]]);
        return $data;
    }

    public function getCourseStudent(){
        $res = input("post.");
        $data = Db::view("student","*")
            ->view("learn",["s_id" => "id"],"learn.s_id=id")
            ->where("c_id","=",$res["c_id"])
            ->select();
        return $data;
    }

    public function getStudentCourse(){
        $res = input("post.");
        $data = Db::view("course","*")
            ->view("learn","c_id","learn.c_id=course.c_id")
            ->where("s_id","=",$res["s_id"])
            ->select();
        return $data;
    }

    public function getScore(){
        $res = input("post.");
        $data = Db::view("learn","s_id,c_id,grade")
            ->view("course",["name" => "c_name"],"course.c_id=learn.c_id")
            ->where("s_id","=",$res["s_id"])
            ->select();
        return $data;
    }
}
